1 package org.apache.maven.surefire.junitcore.pc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.report.ConsoleLogger;
23
24 import java.util.concurrent.CancellationException;
25 import java.util.concurrent.ConcurrentLinkedQueue;
26 import java.util.concurrent.ExecutionException;
27 import java.util.concurrent.ExecutorService;
28 import java.util.concurrent.Future;
29
30
31
32
33
34
35
36
37 final class SharedThreadPoolStrategy
38 extends AbstractThreadPoolStrategy
39 {
40 SharedThreadPoolStrategy( ConsoleLogger logger, ExecutorService threadPool )
41 {
42 super( logger, threadPool, new ConcurrentLinkedQueue<Future<?>>() );
43 }
44
45 @Override
46 public boolean hasSharedThreadPool()
47 {
48 return true;
49 }
50
51 @Override
52 public boolean finished()
53 throws InterruptedException
54 {
55 boolean wasRunningAll = disable();
56 for ( Future<?> futureResult : getFutureResults() )
57 {
58 try
59 {
60 futureResult.get();
61 }
62 catch ( InterruptedException e )
63 {
64
65 wasRunningAll = false;
66 }
67 catch ( ExecutionException e )
68 {
69
70 if ( e.getCause() != null )
71 {
72 logQuietly( e.getCause() );
73 }
74 }
75 catch ( CancellationException e )
76 {
77
78
79
80 }
81 }
82 return wasRunningAll;
83 }
84
85 @Override
86 protected boolean stop()
87 {
88 return stop( false );
89 }
90
91 @Override
92 protected boolean stopNow()
93 {
94 return stop( true );
95 }
96
97 private boolean stop( boolean interrupt )
98 {
99 final boolean wasRunning = disable();
100 for ( Future<?> futureResult : getFutureResults() )
101 {
102 futureResult.cancel( interrupt );
103 }
104 return wasRunning;
105 }
106 }